<template>
  <div>
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @cancel="$emit('close')"
      @confirm="onConfirm"
    />
  </div>
</template>

<script>
import dayjs from 'dayjs'
import { updateUserName } from '@/api/user.js'
export default {
  name: 'UpdateBirthday',
  props: {
    value: {
      value: String,
      required: true
    }
  },
  components: {},
  data () {
    return {
      minDate: new Date(1970, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.value)
    }
  },
  created () {},
  mounted () {},
  methods: {
    async  onConfirm () {
      const birthday = dayjs(this.currentDate).format('YYYY-MM-DD')
      // 发请求
      await updateUserName({ birthday })
      // 关闭弹层
      this.$emit('close')
      // 修改父组件name
      this.$emit('input', birthday)
      // 提示成功
      this.$toast.success('修改成功')
    }
  },
  watch: {},
  computed: {}
}
</script>

<style lang="less" scoped>
</style>
